package metis;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;


public class MetisClustering {

	/**
	 * @param args
	 */
	private String workingDirectory;

	private String binary;

	public MetisClustering(String workingDirectory, String binary) {
		this.workingDirectory = workingDirectory;
		this.binary = binary;
	}

	public void cluster(String inputFileName, int parts) throws IOException, InterruptedException {
		String in = inputFileName;
		int startIndex = 0;
		
		/* convert the data in the right format */
		String cmd = binary+"\\gpmetis.exe "+in+ " " + parts;
		System.out.println(cmd);
		// String path = "C:\\Users\\David\\Desktop\\katsura-clustering\\src";
//		File file = new File("C:\\Users\\David\\Desktop\\SA\\data\\data\\137181_1\\data.mod");
//		System.out.println("Existiert: "+file.exists());
		Process p = null;
		String line;
		
		p = Runtime.getRuntime().exec(cmd, null, new File(workingDirectory));
		BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
		while ((line = input.readLine()) != null) {
			System.out.println(line);
		}
		p.waitFor();
//		System.out.println("Test if file exist: ");
//		file = new File("C:\\Users\\David\\Desktop\\SA\\data\\data\\137181_1\\data.mod");
//		System.out.println("Existiert: "+file.exists());
		
	}
}
